package com.seanchenxi.gwt.wordpress.xmlrpc.service.model.handler;

import java.util.ArrayList;

import com.seanchenxi.gwt.wordpress.domain.model.PageList;
import com.seanchenxi.gwt.wordpress.xmlrpc.service.model.impl.ModelFactory;
import com.seanchenxi.gwt.xmlrpc.client.impl.BaseResponseHandler;

public class PageListsResponseHandler extends BaseResponseHandler<ArrayList<PageList>>{
	
	@Override
	public ArrayList<PageList> handleResponse(String response) {
		Object object = super.handleResponse(response);
		
		if(ModelFactory.isNotList(object)) return null;
		
		ArrayList<PageList> pageLists = new ArrayList<PageList>();
		for(Object obj : (ArrayList<?>)object){
			PageList pageList = ModelFactory.ToPageList(obj);
			if(pageList!=null && !pageLists.contains(pageList)){ 
				pageLists.add(pageList);
			}
		}
			
		return pageLists;
	}
	
}
